package json;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ReadJSONSample {

	public static void main(String[] args) throws IOException, JSONException {
		File file = new File(
				ReadJSONSample.class.getResource("/lidashuai.json")
				.getFile());
		String content = FileUtils.readFileToString(file);
		JSONObject jsonObject = new JSONObject(content);
		if(!jsonObject.isNull("name")){
			
			System.out.println("名字是："+jsonObject.getString("name"));
		}
		System.out.println("年龄是："+jsonObject.getDouble("age"));
		System.out.println("有没有女朋友："+jsonObject.getBoolean("has_girlfriend"));
		JSONArray jsonArray = jsonObject.getJSONArray("major");
		for(int i = 0;i<jsonArray.length();i++){
			System.out.println("技能："+jsonArray.get(i));
		}
	}
}
